/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import java.util.Vector;
import com.hp.hpl.jena.query.*;
/**
 *
 * @author antonio
 */
public class CubixResourceFactory {

    private String graphUri;
    private String subUri;

    public void setOption(String graphUri, String subUri)
    {
        this.graphUri = graphUri;
        this.subUri = subUri;
    }

    public Vector createResource()
    {
        Vector resource = new Vector();

        String queryForResource = "select ?risorsa from <" + this.graphUri + "> where " +
                "{?risorsa <http://unime.it/cubixprop#subLevelCubeOf> " + "\"" + this.subUri + "\"}";

        Query cubixQuery = QueryFactory.create(queryForResource);
        ResultSet results;

        QueryExecution qexec = QueryExecutionFactory.sparqlService("http://localhost:8890/sparql", cubixQuery);

        results = qexec.execSelect();

        for( ; results.hasNext(); )
        {
            QuerySolution soln = results.nextSolution();
            System.out.print("ResourceFactory selected uri: ");
            String var = soln.get("risorsa").toString();
            System.out.print(var + "\t");
            System.out.print("\n\n");

            resource.add(var);
        }

        return resource;
    }

}
